<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>出院管理（出院登记，出院记录）</title>
</head>
<body>
	<script type="text/javascript">
		$(function(){			 
			//出院记录的信息
			$("#out-dg").datagrid({
			    url:'init-outhosprecord2',
			    pagination:true,
      		    pageNumber:1,
      		    pageSize:6,
      		    pageList:[6,12,18],
			    columns:[[
					{field:'out_id',title:'出院号',width:90},
					{field:'clinic_name',title:'病人姓名',width:100},
					{field:'clinic_sex',title:'性别',width:60},
					{field:'clinic_age',title:'年龄',width:60},
					{field:'user_name',title:'主治医生',width:100},
					{field:'section_name',title:'科室',width:80},
					{field:'cash_dmoney',title:'押金余额',width:80},
					{field:'cash_totalmoney',title:'总金额',width:90},
					{field:'out_totalmoney',title:'消费总金额',width:100},
					{field:'out_time',formatter:comFormatDate,title:'出院时间',width:170},
					{field:'out_opreator',title:'经办人',width:86}
			    ]]
			});
			
	
			//所搜住院号查询之前的住院信息
			$("#hospid").searchbox({
				searcher:function(value,name){
					$("#outhospid-record-win").window("open");
				}

			});
			//双击获取住院号
			$("#outhosprecord-dg").datagrid({
				onDblClickRow: function(rowIndex,rowData){
					//住院号
                    $("#hospid").textbox('setValue',rowData.hosp_id);
                    //原床位号的主键
                    $("#bedid").textbox('setValue',rowData.bed_id);
                   
					//原床位号
                    $("#bedno").textbox('setValue',rowData.bed_no);
                    //病人姓名
                    $("#name").textbox('setValue',rowData.clinic_name);
                    $("#doc").textbox('setValue',rowData.user_name);
                    $("#setion").textbox('setValue',rowData.section_name);
                    $("#tmoney").textbox('setValue',rowData.cash_totalmoney);
                    $("#tfee").textbox('setValue',rowData.feemoney);
                    $("#outadvicecontent").textbox('setValue',"多喝热水,按时吃饭");
                    
                    $("#outhospid-record-win").window("close");
				}
				
			});
			
			//住院表的信息
			$("#outhosprecord-dg").datagrid({
			    url:'reg-hosprecord',
			    pagination:true,
      		    pageNumber:1,
      		    pageSize:10,
      		    pageList:[10,15],
			    columns:[[
			    	{field:'hosp_id',title:'住院号',width:100},
					{field:'clinic_name',title:'病人姓名',width:90},
					{field:'clinic_sex',title:'性别',width:60},
					{field:'clinic_age',title:'年龄',width:60},
					{field:'user_name',title:'主治医生',width:90},
					{field:'section_name',title:'科室',width:70},
					{field:'bed_id',title:'主键',width:70,hidden:true},
					{field:'bed_no',title:'床位号',width:70},
					{field:'cash_dmoney',title:'押金余额',width:80,
						styler: function(value,row,index){
							if(value<0){
								return 'color:red;';
							}
							if(value=0){
								return 'color:orange;';
							}
						}
					
					},
					{field:'cash_totalmoney',title:'总金额',width:90},
					{field:'feemoney',title:'消费总金额',width:90},
					{field:'hosp_time',formatter:comFormatDate,title:'登记时间',width:170}
			    ]]
			});
			
			//清空
			$("#out-close-inform").click(function(){
				$('#out-for').form("clear");//清空文本
			});
			
			//出院的确定的按钮
			$("#out-login-inform").click(function(){
				$("#out-for").form({
				    url:'add-outhosptail',
				    onSubmit: function(){
				      var tm = $("#tmoney").val();//总押金
	                  var tfee =  $("#tfee").val();//住院期间消费的总金额
	                  var s =  parseFloat(tm) - parseFloat(tfee) 
	                  if(tfee>tm){
	                	  $.messager.confirm('Confirm', 
	  							'你已欠费【'+s+'】元，请去收费处，暂不出院', 
	  							function(r){
	  					});
	                	  return false;
	                  }
	                  if(tfee<tm){
	                	  $.messager.confirm('Confirm', 
	  							'你的押金余额还剩【'+s+'】元，请去收费处，暂不出院', 
	  							function(r){
	  					});
	                	  return false;
	                  }
				    },
				    success:function(data){
				    	$('#out-for').form("clear");//清空文本
				    	$("#out-dg").datagrid('reload');
				    	$.messager.show({
                            title:'提示信息' , 
                            msg:'出院登记,新增成功!'
                        });
				    	/* $(".window-applydrug").text(date);
				    	$("#warmingapplydurg-win").window('open');
				    	//三秒之后自动消失
					    setTimeout(function(){
					    	 $("#warmingapplydurg-win").window('close');
						  }, 3000); */
				    }
				}).submit();
			});
		});
		
		
		//根据姓名，住院号查询住院登记记录
		function findout(value,name){
			var oid="";
			var cname="";
			if(name=="姓名查询"){
				cname=value;
			}else if(name=="出院号查询"){
				oid = value;
			}
			$("#out-dg").datagrid({
			    url:'init-outhosprecord2',
			    queryParams:{
			    	clinicname:cname,
			    	outid:oid
			    },
			    pagination:true,
      		    pageNumber:1,
      		    pageSize:6,
      		    pageList:[6,12,18],
			    columns:[[
					{field:'out_id',title:'出院号',width:90},
					{field:'clinic_name',title:'病人姓名',width:100},
					{field:'clinic_sex',title:'性别',width:60},
					{field:'clinic_age',title:'年龄',width:60},
					{field:'user_name',title:'主治医生',width:100},
					{field:'section_name',title:'科室',width:80},
					{field:'cash_dmoney',title:'押金余额',width:80},
					{field:'cash_totalmoney',title:'总金额',width:90},
					{field:'out_totalmoney',title:'消费总金额',width:100},
					{field:'out_time',formatter:comFormatDate,title:'出院时间',width:170},
					{field:'out_opreator',title:'经办人',width:86}
			    ]]
			});
		    
       }
		
		
		/**
		 * 时间格式YYY-mm-dd hh:mm:ss
		 */
		function comFormatDate(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
	</script>
	<!--  出院登记 -->
	<fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:1050px;margin: 10px auto;">
		<legend style="font-size:16px;">出院登记信息</legend>
		<form class="out-inform" id="out-for" method="Post">
			<p>
				<a style="margin-left: 32px;">
				<input id="hospid" name="hospId" class="easyui-searchbox" data-options="label:'住院号',height:30" style="width:200px">
				</a>
	    		<a style="margin-left: 50px;">
	    		<input id="name" class="easyui-textbox" data-options="label:'病人姓名',height:30,required:true" style="width:200px">
	    		</a>
	    		<a style="margin-left: 50px;">
	    		<input id="doc" class="easyui-textbox" data-options="label:'主治医生',height:30,required:true" style="width:200px">
	    		</a>
	    		<a style="margin-left: 50px;">
	    		<input id="setion" class="easyui-textbox" data-options="label:'科室',height:30,required:true" style="width:200px">
	    		</a>
			</p>
			<p style="margin-top: 20px;">	
				<input id="bedid" type="hidden" name="bedid" class="easyui-textbox">			
				<a style="margin-left: 30px;">
				<input id="bedno" class="easyui-textbox" data-options="label:'床位号',height:30" style="width:200px">
				</a>
				<a style="margin-left: 50px;">
				<input id="tmoney" class="easyui-textbox" data-options="label:'押金合计',height:30" style="width:200px">
				</a>
				<a style="margin-left: 50px;">
				<input id="tfee" name="outTotalmoney" class="easyui-textbox" data-options="label:'总费用合计',height:30" style="width:200px">
				</a>
				<a style="margin-left: 50px;">
				<input class="easyui-textbox" name="outOpreator" data-options="label:'操作员',height:30" value="${user.userName}" style="width:200px">
				</a>
			</p>
			
			<p style="margin-top: 25px;">	
			    <a style="margin-left: 32px;">
				   <input id="outadvicecontent" class="easyui-textbox" name="outAdvice" data-options="label:'出院建议',height:35" style="width:460px">
				</a>			
				<a style="margin-left:50px;width:90px;" id="out-login-inform" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
			    <a id="out-close-inform" style="margin-left:20px;width:90px;" class="easyui-linkbutton" iconCls="icon-cancel">清空</a>
			</p>
		</form>
	</fieldset>
	
	<!-- 出院记录 -->
	<fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:1050px;height:350px;margin: 20px auto;">
		<legend>出院记录</legend>
			<!-- 搜索框 -->
			<input id="ss" class="easyui-searchbox" style="width:300px"
			    data-options="searcher:findout,prompt:'Please Input Value',menu:'#outhosp'"></input>
			<div id="outhosp" style="width:120px">
			    <div data-options="iconCls:'icon-ok'">姓名查询</div>
			    <div>出院号查询</div>
			</div>
			<table id="out-dg" style="height:260px;" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false">
			</table>
	</fieldset>
	
	<!-- 所搜住院号的窗口 -->
	<div id="outhospid-record-win" class="easyui-window" title="住院的信息(出院界面)" style="width:986px;height:430px"
	    data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		<table id="outhosprecord-dg" style="height:360px;" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false">
		</table>
	</div>
</body>
</html>